package com.zkx.mvp.model.base;

import com.zkx.mvp.api.Constant;

import java.io.Serializable;

/**
 * Author：zhangkx on 2017/6/16 16:42
 * Email：zkx9025@163.com
 */

public class HttpResult<T> implements Serializable {

    /**
     * 返回状态
     */
    private int code;
    //返回状态码
    private int ret;
    private boolean charge;
    /**
     * 提示信息
     */
    private String msg;
    private T result;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isCharge() {
        return charge;
    }

    public void setCharge(boolean charge) {
        this.charge = charge;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public int getRet() {
        return ret;
    }

    public void setRet(int ret) {
        this.ret = ret;
    }

    /**
     * API是否请求成功
     *
     * @return 失败返回false, 成功返回true
     */
    public boolean isSuccess() {
        return code == Constant.WEB_RESP_CODE_SUCCESS||ret == Constant.WEB_RESP_CODE_SUCCESS;
    }

    @Override
    public String toString() {
        return "HttpResult{" +
                "code=" + code +
                ", charge=" + charge +
                ", msg='" + msg + '\'' +
                ", result='" + result + '\'' +
                '}';
    }
}
